package map.DSU;

import java.util.Scanner;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        DSU dsu = new DSU();
        dsu.init(N);
        for (int i = 0; i < M; i++) {
            int S = sc.nextInt();
            int T = sc.nextInt();
            dsu.join(S, T);
        }
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (dsu.find(A) == dsu.find(B)){
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}
